#003-选考难度B-字符串加密-201510-17学考选考
import tkinter as tk

def Code2Char(c):
    s = "IlikeCHNpostcard"
    return s[c]

def encrypt():
    '''加密'''
    s = txt1.get() # 获取明文
    ss = ""
    for ch in s:
        a = ord(ch)
        b1,b2 = divmod(a,16)
        ss = ss + Code2Char(b1) + Code2Char(b2)
    txt2.delete(0,tk.END)
    txt2.insert(0, ss)

# 建立窗口
win = tk.Tk()
win.title('字符串加密')
win.resizable(0, 0)
# 建立组件
lb1 = tk.Label(win, text = '加密前字符串（明文）')
lb2 = tk.Label(win, text = '加密后字符串（密文）')
txt1 = tk.Entry(win)
txt1.insert(0, 'This is an example!')
txt2 = tk.Entry(win,width=40)
cmd = tk.Button(win, text = '加密', command = encrypt)
# 组件布局
lb1.grid(row=0, column=0)
lb2.grid(row=0, column=2)
txt1.grid(row=1, column=0)
txt2.grid(row=1, column=2,columnspan=3)
cmd.grid(row=1,column=1)

# 接收窗口事件
win.mainloop()




